package com.ticket.controller;

import com.ticket.dao.ScheduleDao;
import com.ticket.entity.Drama;
import com.ticket.entity.Hall;
import com.ticket.entity.Movie;
import com.ticket.entity.VSchedule;
import com.ticket.service.HallService;
import com.ticket.service.MovieService;
import com.ticket.service.ScheduleService;
import com.ticket.service.impl.HallServiceImpl;
import com.ticket.service.impl.MovieServiceImpl;
import com.ticket.service.impl.ScheduleServiceImpl;
import com.ticket.util.MybatisUtil;
import com.ticket.util.Page;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @author 王玲娟
 * @version 8.0
 * @description TODO    商家后端管理系统
 * @date 2023-10-08
 */
public class BusinessController {
    //影院影厅安排查询Service
    ScheduleService schs=new ScheduleServiceImpl();
    //影院影厅分页查询
    HallService hs=new HallServiceImpl();
    //影院电影分页查询
    MovieService ms=new MovieServiceImpl();
    /**
    * @author WangLingJuan
    * @description TODO 影院影厅电影的场次安排
    * @date 2023-10-08 13:18
     * @param request
     * @param response
    * @return java.lang.Object
    */

    public Object selVSchedule(HttpServletRequest request, HttpServletResponse response){
        HttpSession session= request.getSession();

        //获取查询条件
        String movieCnName=request.getParameter("movieCnName");//电影中文名称
        String movieHall=request.getParameter("movieHall");//影厅名称
        VSchedule schedule = new VSchedule();
        schedule.setMovieCnName(movieCnName);//电影中文名称
        schedule.setHallName(movieHall);//影厅名称
        //当前页
        String currPageNo=request.getParameter("currPageNo");
        if(currPageNo==null||currPageNo==""){
            currPageNo="1";
        }
        int currPageNoInt=Integer.parseInt(currPageNo);//当前页
        Page<VSchedule> page=new Page<>(8,currPageNoInt);

        Page<VSchedule> schedulePage = schs.selSchedule(schedule, page);
        List<VSchedule> ScheduleDataList = schedulePage.getDataList();//结果集
        int totalPageCount = schedulePage.getTotalPageCount();//总页数
        //将查询出来的结果存入session中
        session.setAttribute("ScheduleDataList",ScheduleDataList);
        session.setAttribute("totalPageCount",totalPageCount);

        return "redirect:/cinema-back-jsp/admin/index/schedule.jsp";
    }
    public Object selHallPage(HttpServletRequest request, HttpServletResponse response){
        HttpSession session = request.getSession();
        Hall hall=new Hall();
        String pageIndex = "1";//获取当前页面
        if (pageIndex == null) {
            pageIndex = "1";
        }
        int pageCurrNo = Integer.parseInt(pageIndex);     //强转为int类型
        Page page = new Page();
        page.setCurrPageNo(pageCurrNo);//设置为当前页
        page.setPageSize(8);        //每页的数量
        session.setAttribute("page", page);
        List<Hall> hallList = hs.showHallpage(page,hall);
        session.setAttribute("hallList",hallList);
        return "redirect:/cinema-back-jsp/admin/index/Menu2.jsp";
    }

    public Object selMoviePage(HttpServletRequest request, HttpServletResponse response){
        HttpSession session = request.getSession();
        String movieName=request.getParameter("movieName");
        Movie movie=new Movie(movieName);
        Page<Movie> page = new Page(8,1);
        String pageIndex = request.getParameter("index");
        if (pageIndex != null) {
            page.setCurrPageNo(Integer.parseInt(pageIndex));//设置为当前页
        }
        page = ms.selMoviePageMovieName(page,movie);
        session.setAttribute("page",page);
        return "redirect:/cinema-back-jsp/admin/index/danye-list.jsp";

    }
}
